package api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import dao.ProductDao;
import donain.User;
import exception.ProductException;
import service.ProductService;
import service.UserService;
import utilts.GetRequestJsonUtils;
import utilts.Response;
import utilts.ResponseCode;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

public class WeekHotBookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        req.getRequestURL();

        Response build=null;
        ProductService productService=new ProductService();
        try {
            List<Object []> hotBooks= productService.getWeekHotProduct();
            build=Response.build(ResponseCode.SUCCESS_QUERY_GOODS,hotBooks);

        } catch (ProductException e) {
            e.printStackTrace();
            build=Response.build(e.getResponseCode());
        }


        resp.getWriter().write(JSON.toJSON(build).toString());
        resp.setContentType("application/json;charset=utf-8");

    }
}
